package interview;

public class interview_04_06 {
    public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
        boolean[] flag=new boolean[1];
        TreeNode[] result=new TreeNode[1];
        inorder(root,flag,result,p);
        return result[0];
    }
    public void inorder(TreeNode node,boolean[] flag,TreeNode[] result,TreeNode p){
        if(node==null) return;
        inorder(node.left,flag,result,p);
        if(flag[0]){
            result[0]=node;
            flag[0]=false;
        }
        if(node==p){
            flag[0]=true;
        }
        inorder(node.right,flag,result,p);
    }
}
